package com.sc.pattern.simplelistener;

import java.util.ArrayList;
import java.util.List;


/**
 * Created  on 2018/1/6.
 *
 * @author sc
 */
public class Subject {
    private List<Observer> observers = new ArrayList<>();

    private int state;

    public int getState() {
        return state;
    }
    public void setState(int state){
        if(state==this.state){
            return;
        }
        this.state =state;
        notifyAllObserver();
    }


    public void attach(Observer observer){
        observers.add(observer);
    }
    public void notifyAllObserver(){
        observers.stream().forEach(Observer::update);
    }



}
